package com.itheima_01;

public class ArrayDemo {
    public static void main(String[]args){
        //数组元素访问
        //定义一个int类型的数组，数组名是arr，数组长度是3
        int[] arr = new int[3];
        int[] arr2 = new int[2];
        //输出数组名
        System.out.println(arr);//[I@ba4d54
        //输出数组中的元素
        int i = 0;
        while (i < 3){
            System.out.println(arr[i]);
            i++;
        }
        System.out.println(arr2);
        System.out.println(arr2[0]);
        System.out.println(arr2[1]);
        //给数组中的元素赋值
        arr[0] = 100;
        arr[2] = 200;
        arr2[0] = 50;
        arr2[1] = 150;
        //输出数组名
        System.out.println(arr);//[I@ba4d54
        //输出数组中的元素
        int j = 0;
        while (j < 3){
            System.out.println(arr[j]);
            j++;
        }
        System.out.println(arr2);
        System.out.println(arr2[0]);
        System.out.println(arr2[1]);

        //多个数组指向相同
        int [] arr3 = new int[2];
        arr3[0] = 1;
        arr3[1] = 2;
        System.out.println(arr3);
        System.out.println(arr3[0]);
        System.out.println(arr3[1]);
        int [] arr4 = arr3;
        arr4[0] = 10;
        arr4[1] = 20;
        System.out.println(arr3);
        System.out.println(arr3[0]);
        System.out.println(arr3[1]);
        System.out.println(arr4);
        System.out.println(arr4[0]);
        System.out.println(arr4[1]);
    }
}
